package com.qmerak.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qmerak.common.SysConstants;
import com.qmerak.dao.impl.UserDao;
import com.qmerak.entity.UserEntity;
import com.qmerak.service.IUserService;

/**
 * @author shaohong.cheng
 * @date 2013-4-11
 */
@Service
public class UserService implements IUserService {
	@Autowired
	private UserDao userDao;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.service.IUserService#verify(com.bean.UserBean)
	 */
	@Override
	public boolean verify(UserEntity userBean) {
		if (userBean.getUserName().equals(SysConstants.SYS_MANAGER_LOGINNAME)) {
			if (userBean.getUserPWD().equals(SysConstants.SYS_MANAGER_PWD)) {
				return true;
			} else {
				return false;
			}
		}
		UserEntity userEntity = userDao.findByName(userBean.getUserName());
		if (userEntity == null) {
			return false;
		}
		if (userEntity.getUserPWD().equals(userBean.getUserPWD())) {
			return true;
		}
		return false;
	}

	public void add(UserEntity entity) {
		userDao.add(entity);
	}

	public void update(UserEntity entity) {
		userDao.update(entity);
	}

	public void delete(UserEntity entity) {
		userDao.remove(entity);
	}

}
